package com.hundsun.s3.mrs.core.chain;

import java.util.HashMap;
import java.util.Map;

public class ChainManager {
	
	/**
	 * key为chain的名称
	 * value为chain
	 */
	private static Map<String, IChain> chains = new HashMap<>();

	public static Chain duplicate(String chainName) {
		Chain chain = (Chain) chains.get(chainName);
		Chain res = new Chain();
		res.setChainName(chainName);
		res.setDesc(chain.getDesc());
		res.setHandlers(chain.getHandlers());
		res.setIndex(0);
		return res;
	}
	
	public static Map<String, IChain> getChains() {
		return chains;
	}

	public static void setChains(Map<String, IChain> chains) {
		ChainManager.chains = chains;
	}
	
	public static void addChain(String name, IChain chain) {
		chains.put(name, chain);
	}
	
	public static void removeChain(String name){
		chains.remove(name);
	}
	public static IChain getChain(String name) {
		return chains.get(name);
	}
	
}